package com.atguigu.tingshu.order.api;

import com.atguigu.tingshu.common.annotation.NeedLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import com.atguigu.tingshu.vo.order.TradeVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "订单管理")
@RestController
@RequestMapping("api/order")
@SuppressWarnings({ "all" })
public class OrderInfoApiController {

    @Autowired
    private OrderInfoService orderInfoService;

    @Operation(summary = "订单确认")
    @PostMapping("/orderInfo/trade")
    @NeedLogin
    public Result<OrderInfoVo> trade(@Validated @RequestBody TradeVo tradeVo) {
        OrderInfoVo orderInfoVo = orderInfoService.trade(tradeVo);
        return Result.ok(orderInfoVo);
    }

    @Operation(summary = "提交订单")
    @PostMapping("/orderInfo/submitOrder")
    @NeedLogin
    public Result<String> submitOrder(@Validated @RequestBody OrderInfoVo orderInfoVo) {
        String orderNo = orderInfoService.submitOrder(orderInfoVo);
        return Result.ok(orderNo);
    }

}
